package com.wzk.canalsync.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wangzikang
 */
//配置线程池
@Configuration
public class ThreadPoolConfig {

    @Bean(name = "operatePool")
    public ExecutorService operatePool(){
        //线程池 只能是单线程 如果使用多线程可能会导致多个任务同时执行 而没有保证顺序
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                1,
                1,
                0L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(5000),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
        return threadPoolExecutor;
    }


}
